#!/usr/bin/env python
#coding:utf-8

from Backend.ConsistHash.ConsistHash import HashRing
import Webconfig
import tornado.ioloop
import tornado.web
from Backend.Core import BladeApplication

from Controllers.HomeController import HomeController

        
class BaseGlobal(object):
    REDISHASHRING = None
    
    def __init__(self):
        pass
    
    def Initialize(self):
        self.ApplicationStart()
    
    def ApplicationStart(self):
        Global.REDISHASHRING = HashRing(nodes = Webconfig.REDIS_HASH_NODES)


class Global(BaseGlobal):
    
    def RegisterRouter(self):
        settings = None
        
        self.__application = BladeApplication.Application([
                                (r'/(?P<controller>(\w+))/(?P<action>(\w+))/',HomeController),
                                (r'/hello/',HomeController),])

    def Start(self):
        
        self.RegisterRouter()
        self.__application.listen(8002)
        tornado.ioloop.IOLoop.instance().start()

if __name__ == '__main__':
    g = Global()
    g.Start()

